The contentShape property defines the interactive or visual boundary shape of a view's content. This shape can influence how a view behaves during interactions such as tapping, dragging, accessibility focus, hover effects, and previews. It is commonly used to fine-tune the hit-testing area or provide a custom visual outline for advanced interaction features.
This is especially useful for views like Button, ListRow, or custom views where the tappable or interactive area should differ from the visual content.
You can specify a standalone Shape to define the default content shape for all purposes.
This applies to all interactions (tap, accessibility, drag, etc.) unless overridden.
You can define a content shape with a specific interaction kind, using the following structure:
This lets you control the content shape behavior in specific contexts (e.g., drag previews or accessibility hit-testing).
ContentShapeKinds| Kind | Description |
|---|---|
"interaction" |
Defines the hit-testing area (taps, clicks, gestures) |
"dragPreview" |
Used for shaping drag-and-drop previews |
"contextMenuPreview" |
Used when displaying a context menu preview |
"hoverEffect" |
Defines the area for hover interactions (e.g., when using pointer devices) |
"accessibility" |
Defines the shape used for accessibility focus, highlighting, and ordering |
contentShape does not alter how the view looks, only how it responds to interactions or previews.contentShape can make tap targets more accessible.